<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <link rel="stylesheet" href="../css/main.css" />
  <link rel="stylesheet" href="../css/login_register/login.css" />
  <!-- 引入样式 -->
  <link rel="stylesheet" href="../css/element.css" />
  <title>登陆</title>
</head>

<body>
  <div id="app" v-cloak>
    <div class="header max_width">
        <div class="wrap">
            <logo></logo>
            <span class="fl login_text">登陆</span>
        </div>
    </div>
    <div class="login_containe max_width">
      <div class="wrap login_wrap">
        <!-- 图片 -->
        <div class="login_pic fl">
          <img src="../images/img_dl.png" alt="" />
        </div>
        <!-- 登陆 -->
        <div class="login_box fr">
          <div class="login_tit">账号登陆</div>
          <div class="username">
            <input type="text" class="fl" v-model="account" />
            <img src="../images/icon_persen.png" alt="" class="fl" />
          </div>
          <div class="password">
            <input type="password" class="fl" v-model="password" @keyup.enter="submit" />
            <img src="../images/icon_suoding.png" alt="" class="fl" />
          </div>
          <div class="forget_num" @click="forget_num">忘记密码</div>

          <div class="login_btn cursor" @click="login_btn">
            登&nbsp;&nbsp;录
          </div>

          <div class="choose_login">
            <div class="wx_login fl">
              <div class="wx_logo fl">
                <a href="https://open.weixin.qq.com/connect/qrconnect?appid=wx34872458373ac732&redirect_uri=http://www.eawgo.com&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect"><img
                    src="../images/icon_wechat.png" alt="" /></a>

              </div>
              <span class="wx_text fl">微信登陆</span>

            </div>
            <div class="register fr cursor" @click="register">立即注册</div>
          </div>
          <!--
              <div class="password write_box">
                  <input type="text" class="write_input">
              </div>
            -->
        </div>
      </div>
    </div>
    <div class="wrap clear_both">
      <productfooter></productfooter>
    </div>
  </div>
  <script src="../js/browser.min.js"></script>
  <script src="../js/vue.js"></script>
  <script src="../js/element.js"></script>
  <script src="../js/axios.js"></script>
  <script src="../js/qs.js"></script>
  <script src="../js/main.js"></script>
  <script type="text/babel">
    var app = new Vue({
        el: "#app",
        data() {
          return {
            password: "",
            account: ""
          };
        },
        components: {},
        methods: {
          submit(e){
            if (e.keyCode==13) {
              if (app.account == "") {
              app.$message.error("请输入用户名");
            } else if (app.password == "") {
              app.$message.error("请输入密码");
            } else {
              axios({
                method: "POST",
                url: base_url + "/user/userLogin",
                data: Qs.stringify({
                  account: this.account,
                  password: this.password
                }),
                headers: {
                  "Content-Type": "application/x-www-form-urlencoded",
                  TOKEN: localStorage.getItem("wACCESS_TOKEN")
                }
              })
                .then(function(res) {
                  if (res.data.code==1) {
                    console.log(res.data)
                    localStorage.setItem("wACCESS_TOKEN",res.data.data.ACCESS_TOKEN);
                    localStorage.setItem("userId",res.data.data.userInfo.id);
                    localStorage.setItem("ryName",res.data.data.imUserInfo.ryName);
                    localStorage.setItem("ryToken",res.data.data.imUserInfo.addString);
                    localStorage.setItem("ryIcon",res.data.data.imUserInfo.ryIcon);
                    localStorage.setItem("ryUserid",res.data.data.imUserInfo.userId);
                    window.location.href = "../../index.html";
                  }else if (res.data.code!=1) {
                    app.$message.error(res.data.msg);
                  }
                  
                })
                .catch(function(error) {
                  console.log(error);
                });
            }
            }
            console.log(e)
          },
          login_btn() {
            // 跳页
            if (app.account == "") {
              app.$message.error("请输入用户名");
            } else if (app.password == "") {
              app.$message.error("请输入密码");
            } else {
              axios({
                method: "POST",
                url: base_url + "/user/userLogin",
                data: Qs.stringify({
                  account: this.account,
                  password: this.password
                }),
                headers: {
                  "Content-Type": "application/x-www-form-urlencoded",
                  TOKEN: localStorage.getItem("wACCESS_TOKEN")
                }
              })
                .then(function(res) {
                  if (res.data.code==1) {
                    localStorage.setItem("wACCESS_TOKEN",res.data.data.ACCESS_TOKEN);
                    localStorage.setItem("userId",res.data.data.userInfo.id);
                    localStorage.setItem("ryName",res.data.data.imUserInfo.ryName);
                    localStorage.setItem("ryToken",res.data.data.imUserInfo.addString);
                    localStorage.setItem("ryIcon",res.data.data.imUserInfo.ryIcon);
                    localStorage.setItem("ryUserid",res.data.data.imUserInfo.userId);
                    window.location.href = "../../index.html";
                  }else if (res.data.code!=1) {
                    app.$message.error(res.data.msg);
                  }
                  
                })
                .catch(function(error) {
                  console.log(error);
                });
            }
          },
          forget_num() {
            window.location.href = "find_password.html";
          },
          register() {
            window.location.href = "register.html";
          }
        }
      });
    </script>
</body>

</html>